﻿
alter PROCEDURE [PomPropertyLetInfoSave]
(
	@pPomplingAddressID INT,
	@pPricePerCalendarMonth DECIMAL,
	@pNumberOfBedrooms INT,
	@pFurnished BIT,
	@pShortDescription VARCHAR(500),
	@pLongDescription VARCHAR(1500),
	@pPropertyType VARCHAR(40),
	@pCustomerID varchar(32)
)
AS
BEGIN
	SET NOCOUNT ON;
	declare @rentalPropertiesCount INT;
	set @rentalPropertiesCount = (select count(*) from PomRentalProperties where PomplingAddressID = @pPomplingAddressID);
	if @rentalPropertiesCount = 0
	BEGIN
		INSERT INTO [PomWebProperties] ([PomplingAddressID], [DateAdded],[NumberOfBedrooms],[ShortDescription],[LongDescription], PomplingCustomerID, PropertyType)
		VALUES (@pPomplingAddressID, GETDATE(), @pNumberOfBedrooms, @pShortDescription, @pLongDescription, @pCustomerID, @pPropertyType );
		INSERT INTO PomRentalProperties (Furnished, PricePerCalendarMonth, PomplingAddressID) values (@pFurnished, @pPricePerCalendarMonth,@pPomplingAddressID);		
	END	ELSE 
	BEGIN
		UPDATE [PomWebProperties]
		SET	[NumberOfBedrooms]=@pNumberOfBedrooms,
		[ShortDescription]=@pShortDescription,
		[LongDescription]=@pLongDescription,
		PropertyType = @pPropertyType
		WHERE PomplingAddressID = @pPomplingAddressID;

		UPDATE PomRentalProperties 
		SET Furnished = @pFurnished,
		PricePerCalendarMonth = @pPricePerCalendarMonth 
		where PomplingAddressID = @pPomplingAddressID
	END
END

